package edu.linyh.night;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Linyh
 * @Description
 * @Date 2022/7/4 20:48
 **/

public class WordUtil {

    public static void generateWord(Map<String, Object> dataMap, String fileName, String templateName, String templatePath) throws Exception {
        Configuration configuration = new Configuration();
        configuration.setDefaultEncoding("UTF-8");

        configuration.setDirectoryForTemplateLoading(new File(templatePath));
        Template t = configuration.getTemplate(templateName, "UTF-8");
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(fileName)), "UTF-8"));
        t.process(dataMap, out);
        out.flush();
        out.close();
    }

}
